package com.xk857.article.controller;

import com.xk857.util.aliyun.AliyunUtil;
import com.xk857.util.base.Result;
import com.xk857.util.enums.PlatformEnum;
import com.xk857.util.properties.BlogProperties;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author CV大魔王
 * @Description 文件控制器
 * @date 2021/2/23 16:10
 */
@Api(value = "文件管理接口", tags = "文件管理接口")
@RestController
@RequestMapping("/pri/file")
public class FileController {

    @Autowired
    private BlogProperties blogProperties;

    @ApiOperation("上传文件到阿里云oss")
    @PostMapping("upload")
    public Result upload(@RequestParam MultipartFile file){
        return AliyunUtil.uploadFileToOss(PlatformEnum.ARTICLE, file, blogProperties.getAliyun());
    }


    @ApiOperation("删除OOS服务器的文件")
    @ApiImplicitParam(name="fileUrl", value="要删除的文件URL", required=true)
    @DeleteMapping("/delete")
    public Result delete(@RequestParam(value = "fileUrl", required = false) String fileUrl) {
        return AliyunUtil.delete(fileUrl, blogProperties.getAliyun());
    }

}
